package config

import (
	"encoding/json"
	"fmt"
	"os"
	"path/filepath"
)

var (
	path string
)

func GetPath(relativePath string) string {
	if "dev" == GetEnv() {
		return GetPathDev(relativePath)
	}
	exePath, err := os.Executable()
	if err != nil {
		fmt.Println("Error getting executable path:", err)
		return ""
	}

	absPath := filepath.Join(filepath.Dir(exePath), relativePath)
	return absPath
}

// GetPathDev /**获取文件路径,用于本地dev*/
func GetPathDev(relativePath string) string {
	absPath, _ := filepath.Abs(relativePath)
	return absPath
}

func ParseJSON(jsonData string, target interface{}) error {
	err := json.Unmarshal([]byte(jsonData), target)
	return err
}
